<?php
include( getcwd() . '/application/views/div/html_head_info.php' );
include( getcwd() . '/application/views/div/header.php' );
?>

<div class="container"> 

<div id="settings">

<p>
	 <?php include( getcwd() . '/application/views/div/user_settings_nav.php' ); ?>
</p>

<h2>
购买记录
</h2>

 <?php
//显示订单列表
if( !empty( $orders ) ){
?>
<table id="user_orders_list">
	<caption>刚提交的订单可能无法显示，请耐心等待系统预处理完成</caption>
	<tr>
		 <th class="span-1 border_radius_top_left">订单号</th>
		 <th class="span-2">商品名称</th>
		 <th class="span-2">购买数量</th>
		 <th class="span-2">支付金额</th>
		 <th class="span-2">购买时间</th>
		 <th class="span-2">状态</th>
		 <th class="span-2 border_radius_top_right">操作</th>
	 </tr>
<?php
	//判断 如果只有一个 order 
        foreach( $orders as $index=>$order ){
?>
	 <tr>	 
<?php
		 echo "<td>{$order['order_sn']}</td>";
		 echo "<td>{$order['product_title']}</td>";
		 echo "<td>{$order['quantity']}</td>";
		 echo "<td>￥{$order['sum_price']}</td>";
		 echo "<td>{$order['time']}</td>";
		 echo "<td class='status'>{$order['status']}</td>";
		 echo "<td class=\"opt\">{$order['opt']}</td>";
?>
	 </tr>
<?php
	}
?>
</table>
<div id="pager_links"><?php echo $pager_links; ?></div>
<?php
}else{
?>
<p>没有任何订单</p>
<?php
}
?>

</div>

</div>

<script type="text/javascript">
//使能取消订单按钮
(function enable_abandon_order(){

	 var abandon_buttons = $( '.abandon' );
	 abandon_buttons.each( function( index , abandon_button ){
		 
		 var this_button = $( abandon_button );
		 var order_sn = this_button.attr( 'id' );

		 this_button.click( function(){
		 
			 $.post( '/deal/ajax_abandon_order/' , { 'order_sn':order_sn } , function( res ){
			 
				if( res.res == 'TRUE' ){
					 
					this_button.parent().parent().find( '.status' ).html( 'ABANDON' );
					this_button.parent().text( '' );
				}else{
				
					 alert( 'oh no !' );
				}
			 } , 'json' );
		 });
	 });
})();
</script>

<?php
include( getcwd().'/application/views/div/footer.php' );
?>
